from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time


# 初始化浏览器驱动对象
driver= webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get(r"file:///C:/TT/%E4%B9%A0%E7%9F%A5/%E6%B5%8B%E5%BC%80%E4%BB%A3%E7%A0%81/python-basic-warehouse-td2/selenium-%E4%B8%8B/selectDemo.html")
time.sleep(3)

# 定位select元素
select_ele = driver.find_element(By.CSS_SELECTOR, "select")
# 使用select元素创建一个下拉框对象
select_obj = Select(select_ele)

# # 通过索引选择
# for i in range(6):
#     select_obj.select_by_index(i)
#     time.sleep(2)

# # 通过value选择
# for value in ['shenzheng', 'beijing', 'chengdu']:
#     select_obj.select_by_value(value)
#     time.sleep(2)

# for text in ['深圳', '北京', '成都']:
#     select_obj.select_by_visible_text(text)
#     time.sleep(2)

print(select_obj.all_selected_options)
print(select_obj.first_selected_option)
print(select_obj.is_multiple)
print(select_obj.options)

time.sleep(5)
driver.quit()